<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>小鱼ADMIN</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/public/static/css/font.css">
    <link rel="stylesheet" href="/public/static/css/bgadmin.css">
    <script type="text/javascript" src="/public/static/js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/public/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/public/static/js/bgadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <style>
  .layui-input{height:30px;}
  .layui-form-label{line-height: 16px;}
  .layui-btn-gray{background-color:#c2c2c2;}
  </style>
  <body>
    <div class="bg-body">
      <div class="layui-row">
        <form class="layui-form ">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label" onclick="clearInput ('name')">客户姓名：</label>
              <div class="layui-input-inline">
                <input type="text" name="name" lay-verify="" id="name" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label" onclick="clearInput ('phone')">手机：</label>
              <div class="layui-input-inline">
                <input type="text" name="phone" id= "phone" lay-verify="" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label" onclick="clearInput ('import_mark')">导入标记：</label>
              <div class="layui-input-inline">
                <input type="text" name="import_mark" id= "import_mark" lay-verify="" autocomplete="off" class="layui-input">
              </div>
            </div>
            <a class="layui-btn layui-btn-small" style="margin-bottom: 10px;" id="search"  lay-submit="" lay-filter="search"><i class="layui-icon" >&#xe615;</i></a>
            <a class="layui-btn layui-btn-small" style="margin-bottom: 10px;" lay-submit="" onclick="joinAutoCallQueue()"><i class="layui-icon" >签入</i></a>
            <a class="layui-btn layui-btn-small" style="margin-bottom: 10px;" lay-submit="" onclick="moveAutoCallQueue()"><i class="layui-icon" >签出</i></a>

        </form>
      </div>

      <table class="layui-table" lay-data="{id: 'customer_code', height:'full-200', url:'/index.php/crm/Callplatform/saleSourceData?id={$task_id}', page:true, limit:10, limits:[10,20,30,50]}" lay-filter="demo">
        <thead>
        <tr>
          <th lay-data="{checkbox:true, fixed: true}"></th>
          <th lay-data="{field:'customer_code', align:'center', width:180, fixed: 'left'}">会员编码</th>
          <th lay-data="{field:'name', width:100, align:'center', fixed: 'left'}">会员姓名</th>
          <th lay-data="{field:'phone1', width:120, align:'center'}">客户手机</th>
          <th lay-data="{field:'calledflag', width:120, align:'center'}">呼叫状态</th>
          <th lay-data="{field:'import_mark', width:150, align:'center'}">导入标记</th>
          <th lay-data="{field:'address', width:250, align:'center'}">导入地址</th>
          <th lay-data="{field:'createtime', width:150, align:'center'}">创建时间</th>
        </tr>
        </thead>
      </table>
    </div>
</body>
<!-- <script type="text/javascript" src="/public/static/crm/js/servicecustomer/customerList.js"></script> -->
<script>
    var id='{$task_id}';

    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
            // console.log(obj)
        });

        //重载数据表
        $('#search').click(function(){
            // location.replace(location.href);
            var name = $("#name").val();
            var phone = $("#phone").val();
            var import_mark = $("#import_mark").val();
            var sex = $("#sex").val();
            table.reload('customer_code', {
                url: 'saleSourceData?id={$task_id}',
                where: {
                    name : name,
                    phone : phone,
                    import_mark : import_mark,
                    sex : sex,
                } //设定异步数据接口的额外参数
            });
        });
    });

    $(document).on('dblclick', '.layui-table>tbody>tr', function (){
        var customer_code = $(this).children('td:eq(1)').text();
        bg_full_show('编辑资料','/index.php/crm/Callplatform/editMyCustomer.html?customer_code='+customer_code+'&id='+id)
    })

    function clearInput (id) {
        $('#'+id).val('');
    }

    function addSearchNum (id, num, num2) {
        $('#'+id).val(num);
        if (num2) {
            $('#'+id+'2').val(num2);
        }
    }


    function joinAutoCallQueue(exten){
        var exten = "{$extension}";
        var task_id = "{$task_id}";
        // alert(task_id);
        // alert(exten);return ;
        //确保选择了项目id
        if(! task_id ){
            layer.alert('请先选择项目', {icon: 5}, function(index){
                layer.close(index);
            });
        }else{
            $.ajax({
                type: "get",
                url: "http://192.168.88.59:8888/agent.php?m=Telemarketing&a=joinAutoCallQueue&exten="+exten+"&task_id="+task_id, 
                /*contentType:"application/json; charset=utf-8",
                dataType : 'jsonp',*/
                success: function (status) {
                    if( status == "OK" ){
                        layer.alert('签入成功,请准备接听电话', {icon: 6}, function(index){
                            layer.close(index);
                        });
                    }else{
                        layer.alert('签入失败,确认您是否已经签入', {icon: 5}, function(index){
                            layer.close(index);
                        });
                    }
                    
                },
                error: function (XMLHttpRequest, textStatus, errorThrown){ 
                    layer.alert('发生未知错误', {icon: 5}, function(index){
                        layer.close(index);
                    });
                    // alert(XMLHttpRequest.readyState)
                }
            });
        }
    }


    //迁出电话到外呼队列
    function moveAutoCallQueue(exten){
        var exten = "{$extension}";
        var task_id = "{$task_id}";
        //确保选择了项目id
        if(! task_id ){
            layer.alert('请先选择项目', {icon: 5}, function(index){
                layer.close(index);
            });
        }else{
            $.ajax({
                type: "get",
                url: "http://192.168.88.59:8888/agent.php?m=Telemarketing&a=moveAutoCallQueue&exten="+exten+"&task_id="+task_id, 
                success: function (status) {
                    if( status == "OK" ){
                        layer.alert('签出成功', {icon: 6}, function(index){
                            layer.close(index);
                        });
                    }else{
                        layer.alert('签出失败,确认您是否已经签出', {icon: 5}, function(index){
                            layer.close(index);
                        });
                    }
                    
                },
                error: function (XMLHttpRequest, textStatus, errorThrown){ 
                    layer.alert('发生未知错误', {icon: 5}, function(index){
                        layer.close(index);
                    });
                }
            });
        }
    }

</script>
</html>